﻿using JTActiveSafety.Gateway.Abstractions;
using JTActiveSafety.Gateway.Services;
using JTActiveSafety.Gateway.Sessions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;


namespace JTActiveSafety.Gateway.Jobs
{
    //public class JTActiveSafetySessionNoticeJob : BackgroundService
    //{
    //    private readonly ILogger logger;
    //    private JTActiveSafetySessionNoticeService SessionNoticeService;
    //   // private JTActiveSafetyHttpSessionManager HttpSessionManager;
    //    public JTActiveSafetySessionNoticeJob(
    //        JTActiveSafetySessionNoticeService sessionNoticeService,
    //        ILoggerFactory loggerFactory
    //        /*,[AllowNull]JTActiveSafetyHttpSessionManager jT1078HttpSessionManager=null*/)
    //    {
    //        logger = loggerFactory.CreateLogger<JTActiveSafetySessionNoticeJob>();
    //        SessionNoticeService = sessionNoticeService;
    //        //HttpSessionManager = jT1078HttpSessionManager;
    //    }

    //    protected override async Task ExecuteAsync(CancellationToken stoppingToken)
    //    {
    //        await Task.Run(() => {
    //            try
    //            {
    //                //foreach (var notice in SessionNoticeService.SessionNoticeBlockingCollection.GetConsumingEnumerable(stoppingToken))
    //                //{
    //                //    if (logger.IsEnabled(LogLevel.Information))
    //                //    {
    //                //        logger.LogInformation($"[Notice]:{notice.SIM}-{notice.ProtocolType}-{notice.SessionType}");
    //                //    }
    //                //    if(JTActiveSafetyGatewayConstants.SessionOffline== notice.SessionType)
    //                //    {
    //                //        if (HttpSessionManager != null)
    //                //        {
    //                //            //当1078设备主动断开的情况下，需要关闭所有再观看的连接
    //                //            HttpSessionManager.TryRemoveBySim(notice.SIM);
    //                //        }
    //                //    }
    //                //}
    //            }
    //            catch
    //            {

    //            }
    //        }, stoppingToken);
    //    }
    //}
}
